package cn.gzjp.modules.wx.service;

import java.util.List;

import cn.gzjp.common.utils.CacheUtils;
import cn.gzjp.modules.sys.entity.Role;
import cn.gzjp.modules.sys.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gzjp.common.persistence.Page;
import cn.gzjp.common.service.CrudService;
import cn.gzjp.modules.wx.entity.WxMpAccount;
import cn.gzjp.modules.wx.dao.WxMpAccountDao;

/**
 * 小程序配置信息Service
 * @author zengcp
 * @version 2018-04-03
 */
@Service
@Transactional(readOnly = true)
public class WxMpAccountService extends CrudService<WxMpAccountDao, WxMpAccount> {

	public static final String MPACCOUNT_CACHE = "mpAccountCache";


	public WxMpAccount get(String id){
		WxMpAccount mpAccount = (WxMpAccount) CacheUtils.get(MPACCOUNT_CACHE, MPACCOUNT_CACHE + id);
		if (mpAccount ==  null){
			mpAccount = super.get(id);
			if (mpAccount == null){
				return null;
			}

			CacheUtils.put(MPACCOUNT_CACHE, MPACCOUNT_CACHE + mpAccount.getId(), mpAccount);
		}
		return mpAccount;
	}
	
	public List<WxMpAccount> findList(WxMpAccount wxMpAccount) {
		return super.findList(wxMpAccount);
	}
	
	public Page<WxMpAccount> findPage(Page<WxMpAccount> page, WxMpAccount wxMpAccount) {
		return super.findPage(page, wxMpAccount);
	}
	
	@Transactional(readOnly = false)
	public void save(WxMpAccount wxMpAccount) {
		WxMpAccount m = get(wxMpAccount.getId());
		if(m!=null){
			super.save(wxMpAccount);
		}else{
			super.insert(wxMpAccount, wxMpAccount.getId());
		}
		CacheUtils.remove(MPACCOUNT_CACHE, MPACCOUNT_CACHE + wxMpAccount.getId());
	}
	
	@Transactional(readOnly = false)
	public void delete(WxMpAccount wxMpAccount) {
		super.deleteByLogic(wxMpAccount);
	}
	
}